package cn.edu.nuc.ssm.dao;

import cn.edu.nuc.ssm.entity.User;
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface UserMapper {
    @Delete({
        "delete from user",
        "where id = #{id,jdbcType=INTEGER}"
    })
    int deleteByPrimaryKey(Integer id);

    @Insert({
        "insert into user (id, username, ",
        "password, email, ",
        "age, sex",
        ")",
        "values (#{id,jdbcType=INTEGER}, #{username,jdbcType=VARCHAR}, ",
        "#{password,jdbcType=VARCHAR}, #{email,jdbcType=VARCHAR}, ",
        "#{age,jdbcType=INTEGER}, #{sex,jdbcType=TINYINT} ",
        ")"
    })
    @SelectKey(statement = "SELECT LAST_INSERT_ID()",
            keyProperty = "id",before = false,resultType = Integer.class)
    int insert(User record);

    int insertSelective(User record);

    @Select({
        "select",
        "id, username, password, email, age, sex,pic",
        "from user",
        "where id = #{id,jdbcType=INTEGER}"
    })
    @ResultMap("cn.edu.nuc.ssm.dao.UserMapper.BaseResultMap")
    User selectByPrimaryKey(Integer id);

    int updateByPrimaryKeySelective(User record);

    @Update({
        "update user",
        "set username = #{username,jdbcType=VARCHAR},",
          "password = #{password,jdbcType=VARCHAR},",
          "email = #{email,jdbcType=VARCHAR},",
          "age = #{age,jdbcType=INTEGER},",
          "sex = #{sex,jdbcType=TINYINT}",
          "",
          "",
        "where id = #{id,jdbcType=INTEGER}"
    })
    int updateByPrimaryKey(User record);




    List<User> findByUsername(@Param("username")String username);

    List<User> findByUsernameAndPassword(@Param("username")String username,@Param("password")String password);


    User findbyId(@Param("id")Integer id);


    List<User> find();

    int updateStatus(@Param("id")Integer id);


    int updateStatus1(@Param("id")Integer id);




    int updatepicbyId(@Param("updatedPic")String updatedPic,@Param("id")Integer id);


    String findpicbyId(@Param("id")Integer id);




}